﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UniMana.Utils.Controls;
using UniMana.Data;
namespace UniMana.Data
{
    public class Training_SubjectOpenRequestInfo
    {
        private bds m_bds = new bds();
        private DBMain m_data = new DBMain();
        private bool m_bExits = false;

        public Training_SubjectOpenRequest Properties
        {
            get { return this.m_bds.Current as Training_SubjectOpenRequest; }
        }

        public void Delete()
        {
            this.m_bds.DeleteCurrent();
        }

        public void Save()
        {
            this.m_bds.EndEdit();
            this.m_data.m_DCSave.SubmitChanges();
        }

        public Training_SubjectOpenRequestInfo(int _iRequestOpenKey = -1)
        {
            var iQuery = this.m_data.m_DCSave.Training_SubjectOpenRequests.Where(
                p => p.Training_SubjectOpenRequestKey == _iRequestOpenKey);
            this.m_bds.DataSource = iQuery;
            var row = iQuery.FirstOrDefault();
            this.m_bExits = true;
            if (row == null)
            {
                this.m_bExits = false;
                row = new Training_SubjectOpenRequest();
                this.m_bds.Add(row);
                this.m_bds.MoveLast();
            }
        }

        public bool ExistInDatabase
        {
            get { return this.m_bExits; }
        }
    }
}
